home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TIMING.SWG / 0008_Release Time Slices.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  71 lines

  1. {
  2. Some months ago we discussed the problem With Dos Programs
  3. that eats CPU time in multitask environments (as OS/2),
  4. when they're idle.  I have successfully used an Inline
  5. statement in my Pascal Programs that calls intr $28, which
  6. is the Keyboard Busy Flag, For this purpose.  I found that
  7. Inline statement in a TurboPower Program, which they use
  8. to signalize to TSRs that it's OK to interrupt processing.
  9.  
  10. Here's the Inline statement I use in keyboard loops:
  11.  
  12.     Inline($CD/$28);
  13.  
  14. But...  This statement doesn't work in the Idle method of
  15. Turbo Vision Programs...  In our previous discussion on
  16. this subject, somebody here looked up another intr in
  17. Ralph Brown's excellent Compilation list of interrupts.
  18. This intr, $2F, works in another way by releasing the
  19. reminder of unused time-slice to the operating system.
  20. Called in a tight Program loop, this means that the
  21. Program will free up it's idle time to the OS.
  22.  
  23. Here's a Function I made that I now use in TV's Idle method:
  24. }
  25.  
  26. Uses
  27.   Dos;
  28.  
  29. Function  ReleaseTimeSlice: Boolean;
  30. Var
  31.   Regs: Registers;
  32.  
  33. begin
  34.   With Regs do
  35.   begin
  36.     AX := $1680;
  37.     Intr($2F, Regs);
  38.     ReleaseTimeSlice := (AL = $00);  { AL=$80 if not supported by OS }
  39.   end;
  40. end;
  41.  
  42. {
  43.  ...and here's how the Idle loop Uses it in a TV Program:
  44. }
  45.  
  46. Procedure TMyProgram.Idle;
  47. begin
  48.   TApplication.Idle;
  49.  
  50.   { more idle calls go here ... }
  51.   {  :                          }
  52.  
  53.   { Inline($CD/$28); }  { this has no effect on PULSE.EXE by itself }
  54.   ReleaseTimeSlice;     { remember to use $X+ when Compiling the Program }
  55. end;
  56.  
  57. {
  58. ...This works fine, judging by PULSE.EXE in OS/2.
  59. Ralph Brown also says this works in Windows, tho Windows
  60. native Programs may not use it.
  61. Maybe someone can comment on if it's necesarry to also
  62. put in the Inline statement above For servicing TSRs.
  63. I can't see any reason For not doing it, but I might've
  64. overlooked something here...  :-)
  65.  
  66. Borland doesn't do this in their Idle method For TP/BP.
  67. It should be quite easy to patch this in the RTL code,
  68. For those of you that have it, and reCompile BP.
  69. }
  70.  
  71.